class BiTreeNode:
    def __init__(self, data):
        self.data = data
        self.lchild = None  # 左孩子
        self.rchild = None  # 右孩子

# 前序遍历
def per_order(root):
    if root:
        print(root.data,end=",")
        per_order(root.lchild)
        per_order(root.rchild)
def per_order_list(root):
    if root:
        return [root.data] + per_order_list(root.lchild) + per_order_list(root.rchild)
    return []


# 中序排列
def in_order(root):
    if root:
        in_order(root.lchild)
        print(root.data,end=",")
        in_order(root.rchild)       
        

# 后序排序
def post_order(root):
    if root:
        post_order(root.lchild)
        post_order(root.rchild)        
        print(root.data,end=",")


a = BiTreeNode("A")
b = BiTreeNode("B")
c = BiTreeNode("C")
d = BiTreeNode("D")
e = BiTreeNode("E")
f = BiTreeNode("F")
g = BiTreeNode("G")

e.lchild = a
e.rchild = g
a.rchild = c
c.lchild = b
c.rchild = d
g.rchild = f
root = e

print(e.lchild.rchild.data)

per_order(e)
print()
print(per_order_list(root))
post_order(e)
